/*
 * @Author: CodeHare
 * @Date: 2023-09-27 10:59:53
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-25 14:13:48
 * @Description: 站点数据总览页
 */
import 'package:bruno/bruno.dart';
import 'package:yt_devops/utils/enums.dart';

class ChargingStationModel {
  ChargingStationModel();
  DateTimePickerMode pickerMode = DateTimePickerMode.day;

  ///  充电桩实时功率源数据
  List<ChaStaRealPower> chaStaRealPower = [];

  /// 充电桩实时功率 Echarts 所需数据
  List<dynamic> chaStaPowerDataList = [];
  List<dynamic> powerUseRateList = [];
  List<dynamic> powerTimeList = [];

  /// 充电电量 Echarts 所需数据
  List<dynamic> chargingOrderCount = [];

  /// 充电次数 Echarts 所需数据
  List<dynamic> chargingTimes = [];
  List<dynamic> chargingCapacityList = [];
  List<dynamic> trendsTimeList = [];

  /// 时间 Echarts 所需数据
  List<dynamic> chargingFee = [];

  /// 终端设备列表元数据
  List<ChargingSubDevice> terminalDeviceOriginList = [];

  /// 终端设备列表数据
  List<ItemEntity> terminalDeviceList = [];
}

/// 分体桩子设备
class ChargingSubDevice {
  /// 设备id
  int? deviceId;

  /// 设备名称
  String? name;

  ChargingSubDevice({
    this.deviceId,
    this.name,
  });

  factory ChargingSubDevice.fromJson(Map<String, dynamic> json) =>
      ChargingSubDevice(
        deviceId: json["deviceId"],
        name: json["name"],
      );
}

/// 累计充电量、充电次数
class ChargeTerminalTrend {
  /// 累计充电次数
  int chargeCountTotal;

  /// 累计充电量
  double chargeElectricityTotal;

  /// 充电桩终端充电趋势源数据
  List<ChargeElectricityCount>? chaStaTerChagTrend;

  ChargeTerminalTrend({
    this.chargeCountTotal = 0,
    this.chargeElectricityTotal = 0.0,
    this.chaStaTerChagTrend,
  });

  factory ChargeTerminalTrend.fromJson(Map<String, dynamic> json) =>
      ChargeTerminalTrend(
        chargeCountTotal: json["chargeCountTotal"],
        chargeElectricityTotal: json["chargeElectricityTotal"],
        chaStaTerChagTrend: List<ChargeElectricityCount>.from(
            json["list"].map((x) => ChargeElectricityCount.fromJson(x))),
      );
}

class ChargeElectricityCount {
  ///充电次数
  double? chargeCount = 0;

  ///充电电量
  double? chargeElectricity = 0.0;

  ///时间
  String? time;

  String get getTime {
    return time!.substring(0, 5);
  }

  ChargeElectricityCount({
    this.chargeCount,
    this.chargeElectricity,
    this.time,
  });

  factory ChargeElectricityCount.fromJson(Map<String, dynamic> json) =>
      ChargeElectricityCount(
        chargeCount: json["chargeCount"],
        chargeElectricity: json["chargeElectricity"],
        time: json["time"],
      );

  Map<String, dynamic> toMap() => {
        "chargeCount": chargeCount,
        "chargeElectricity": chargeElectricity,
        "time": time,
      };
}

/// 充电桩实时功率
class ChaStaRealPower {
  ///值，示例：0
  double? power;
  double? powerUseRate;

  ///时间，示例：2023-08-01 23:55:00
  String? time;

  ChaStaRealPower({
    this.time,
    this.power,
    this.powerUseRate,
  });

  String get getTime {
    if (time == null) {
      return '';
    } else {
      return time!.substring(11, 16);
    }
  }

  factory ChaStaRealPower.fromJson(Map<String, dynamic> json) =>
      ChaStaRealPower(
        power: json["power"],
        powerUseRate: json["powerUseRate"],
        time: json["time"],
      );

  Map<String, dynamic> toMap() => {
        "power": power,
        "powerUseRate": powerUseRate,
        "time": time,
      };
}
